package com.example;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.text.StrFormatter;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.StrUtil;
import io.milvus.grpc.IDs;
import lombok.Data;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;

@Data
public class OpenAiChatMessage {

    public static String getBase64Decode(String str) {
        if (str == null || "".equals(str)) {
            return "";
        }
        char[] ch = str.toCharArray();
        byte[] bt = Base64.decode(String.valueOf(ch));
        try {
            str = new String(bt,"UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return str;
    }

    public static String format(String template, String[] params) {
        if (null == template) {
            return "null";
        } else {
            return !ArrayUtil.isEmpty(params) && !StrUtil.isBlank(template) ? StrFormatter.format(template.toString(), params) : template.toString();
        }
    }

    public static void main(String[] args) throws Exception {
//        String str = "你现在是一名专业的诗歌创作者，请以{}为主题写一首{}风格的诗歌，创作手法模仿{}，篇幅为{}。";
//        String [] params = {"1","2","3","4"};
//        String result = OpenAiChatMessage.format(str, params);
//        System.out.println(result);
//        List<String> strings = new ArrayList<>();
//        strings.add("1");
//        System.out.println(strings);
//        List<String> add = null;
//        strings.addAll(add);
//        System.out.println(strings);

//        String str = "[1, 2, 3]";
//        String newStr = str.replaceAll(", ", ",");
//        System.out.println(newStr);

        List<Long> ids = new ArrayList<>();
        ids.add(0L);
        ids.add(1L);
        ids.add(2L);
        System.out.println(ids.toString());
        String str = ids.toString();
        String newStr = str.replaceAll(", ", ",");
        System.out.println(newStr);

        String s = "1" + 1 + "1";
        System.out.println(s);

    }
}
